<?php

class Index extends TPage
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->Master->pageHead->Title = $this->Application->Parameters["WEBSITE_TITLE"];
		$this->Master->cssMenuHome->Value = "current_menu_item";

		if (!$this->IsPostBack)
		{	
			// Populate Cuisine List
			$this->cboCuisineSelector->DataSource = CuisineRecord::finder()->getAllItems();
			$this->cboCuisineSelector->DataBind();
			
			// Populate MRT List
			$this->cboMRTSelector->DataSource = MRTRecord::finder()->getAllItems();
			$this->cboMRTSelector->DataBind();
			
			// Populate Close Time List
			$this->cboCloseTimeSelector->DataSource = CloseTimeRecord::finder()->getAllItems();
			$this->cboCloseTimeSelector->DataBind();
			
			$this->renderBoxRecommendedFoodPlaces();
			$this->renderBoxSlideshowBanners();
		}
	}
	
	protected function renderBoxRecommendedFoodPlaces()
	{
		$limit = 6;
		$offset = null;
		$sqlmap = $this->Application->Modules['sqlmap']->Client;
		$items = $sqlmap->queryForList("GetRecommendedFoodPlaceList", null,null,$offset,$limit);
		$this->ListRecommendedFoodPlace->DataSource = $items;
		$this->ListRecommendedFoodPlace->DataBind();	
	}

	protected function renderBoxSlideshowBanners()
	{
		$limit = null;
		$offset = null;
		$sqlmap = $this->Application->Modules['sqlmap']->Client;
		$items = $sqlmap->queryForList("GetSlideshowBannerList", null,null,$offset,$limit);
		$this->SlideshowBanners->DataSource = $items;
		$this->SlideshowBanners->DataBind();	
	}
	
	protected function btnSearch_Clicked($sender, $param)
	{
		$searchCuisine = $this->cboCuisineSelector->SelectedValue;
		$searchMRT = $this->cboMRTSelector->SelectedValue;
		$searchTime = $this->cboCloseTimeSelector->SelectedValue;

		$this->Response->redirect($this->Service->ConstructUrl('FoodPlaces', array('cid'=>$searchCuisine,'mrt'=>$searchMRT,'time'=>$searchTime)));						
	}
}

?>